<template>
  <div class="departments-container">
    <div class="app-container">
      <el-card>
        <TreeTools :tree-node="company" :is-root="true" />
        <!-- 树形组件学习 -->
        <el-tree :data="departs" :props="defaultProps">
          <!-- <el-row slot-scope="{ data }" type="flex" align="middle" style="height: 40px; width: 100%"> -->
          <!-- <template v-slot:default="{ data }"> -->
          <!-- v-slot简写为 # -->
          <template #default="{data}">
            <TreeTools :tree-node="data" />
          </template>
        </el-tree>
      </el-card>
    </div>
  </div>
</template>

<script>
import TreeTools from '@/views/departments/components/tree-tools.vue'
export default {
  name: 'Departments',
  components: { TreeTools },
  data() {
    return {
      company: {
        name: '江苏传智播客教育科技股份有限公司',
        manager: '负责人'
      },
      defaultProps: {
        // 默认就是下面的样式，找 label 这个 key 对应 value 作为文字展示
        // label: 'label',
        // 希望用 name 这个 key 对应的 value 作为文字展示
        label: 'name'
        // 默认通过 children 找孩子
        // children: 'children'
      },
      departs: [{
        name: '总裁办',
        manager: '曹操',
        children: [{
          name: '董事会',
          manager: '曹丕'
        }]
      },
      {
        name: '行政部',
        manager: '刘备'
      },
      {
        name: '人事部',
        manager: '孙权'
      }
      ]
    }
  }
}
</script>

<style lang="scss" scoped>
    .el-tree {
        ::v-deep {
            // 小三角的样式, 去掉默认的小三角的旋转效果
            .el-tree-node__expand-icon.expanded {
                -webkit-transform: rotate(0deg);
                transform: rotate(0deg);
            }
            // 有子节点 且未展开 +
            .el-icon-caret-right:before {
                background: url('~@/assets/common/add-circle.png') no-repeat 0 0;
                content: '';
                display: block;
                width: 16px;
                height: 16px;
                font-size: 16px;
                background-size: 16px;
            }
            // 有子节点 且已展开 -
            .el-tree-node__expand-icon.expanded.el-icon-caret-right:before {
                background: url('~@/assets/common/minus-circle.png') no-repeat 0 0;
                content: '';
                display: block;
                width: 16px;
                height: 16px;
                font-size: 16px;
                background-size: 16px;
            }
            // 没有子节点
            .el-tree-node__expand-icon.is-leaf::before {
                background: url('~@/assets/common/user-filling.png') no-repeat 0 0;
                content: '';
                display: block;
                width: 16px;
                height: 16px;
                font-size: 16px;
                background-size: 16px;
            }
        }
    }
</style>
